package com.yh.homestay.common;



 
 
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class Send {
	 
	private static final String AccessKeyId = "LTAIdni6dhtl4DgC";
	private static final String AccessKeySecret = "0fqcEDStXbTWs59ODCQHTNi9OlIAd0";
	private static IAcsClient acs = null;
	private static SendSmsRequest req = new SendSmsRequest();
	static {
		IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", AccessKeyId, AccessKeySecret);
		try {
			DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
		} catch (ClientException e) {
			e.printStackTrace();
		}
		acs = new DefaultAcsClient(profile);
	}

	public static boolean sendCode(String mobile, String username, String number, String address) throws ClientException {

		req.setPhoneNumbers(mobile);
		req.setSignName("艾虹先");
		req.setTemplateCode("SMS_182541875");
		//req.setTemplateParam("{\"code\":\"" + code + "\"}");
		req.setTemplateParam("{\"username\":\"" + username + "\","+"\"number\":\"" +number+"\","+"\"address\":\""+address+
				"\","+"}");
		SendSmsResponse res = acs.getAcsResponse(req);
		 
		System.out.println("res code: "+ res.getCode());
		System.out.println("res message: "+res.getMessage());
		 
		return res.getCode() != null && res.getCode().equals("OK");
	}
	/*public static void main(String[] args) throws ClientException {
		sendCode("13937416991", "123412");
	}*/
}
